<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Town_model extends CI_Model
{
	function __construct(){
        parent::__construct();
	}
	
	function get_all($num,$offset)
	{
		$this->db->order_by('sort_no','ASC');
		$this->db->order_by('town_id','ASC');
		return $this->db->get('rv_town',$num,$offset)->result();
	}
	
	function get_num()
	{
		 return $this->db->get('rv_town')->num_rows();          
	}
	
	function del($id)
	{
		 $this->db->where('town_id',$id);
		 if($this->db->delete('rv_town')){
			  return true;
		 }else{
			  return false;
		 }
	}
	
	function save($data)
	{
		 $id = (int)$this->uri->segment(3);
		 if($id != 0){
			  $this->db->where('town_id',$id);
			  if($this->db->update('rv_town',$data)){
					return true;
			  }else{
					return false;
			  }
		 }else{

			  if($this->db->insert('rv_town',$data)){
					return true;
			  }else{
					return false;
			  }
		 }          
	}
	function get($id=0)
	{
		 $this->db->where('town_id',$id);
		 return $this->db->get('rv_town')->row();
	}
	
	function get_list_country(){
		 $this->db->order_by('lb_country','ASC');
		 return $this->db->get('fm_country')->result();
	}
	function get_country()
	{
		$this->db->order_by('town_id','ASC');
		return $this->db->get('rv_town')->result();
	}
	function get_national()
	{
		$this->db->order_by('countryid','ASC');
		return $this->db->get('locations_country')->result();
	}
}
